package com.todo.biz.application.handler.bizData;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.todo.biz.application.entity.context.SimpleBusinessDataContext;
import com.todo.common.common.enums.BusinessSceneEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author azhebuxing
 * @date 2024/5/30 10:57
 * @description
 */
@Slf4j
public abstract class AbstractBusinessDataHandle {

    /**
     * 查询业务基础数据，如果是平台创建则给到默认平台用户信息
     * 主要是点赞、收藏、关注等信息
     *
     * @param bizIdList
     * @return
     */
    public Map<Long/*bizId*/, SimpleBusinessDataContext> querySimpleBizData(List<Long> bizIdList) {
        if (CollectionUtils.isEmpty(bizIdList)) {
            return Maps.newHashMap();
        }
        Map<Long, SimpleBusinessDataContext> result = doQueryBizData(bizIdList);
        List<Long> missIdList = new ArrayList<>();
        for (Long bizId : bizIdList) {
            if (!result.containsKey(bizId)) {
                missIdList.add(bizId);
            }
        }
        if (CollectionUtils.isNotEmpty(missIdList)) {
            log.warn("AbstractBusinessDataHandle#querySimpleBizData 关联数据存在缺失，缺失数据Id列表：【{}】", JSONObject.toJSONString(missIdList));
        }
        return result;
    }

    protected abstract Map<Long, SimpleBusinessDataContext> doQueryBizData(List<Long> bizIdList);

    public abstract BusinessSceneEnum getHandleBusinessScene();
}
